import CONSTANT from './constants'
import http from './http'
var weixinSendAppMessage = function (title) {
  let thisPageUrl = window.location.href.split('#')[0]
  http.post(CONSTANT.WXCONFIG, {'url': thisPageUrl}, (res) => {
    if (res.code == 200) {
      console.log('config参数已返回')
      console.log(res)
      this.wx.config({
        "debug": false,
        "appId": res.obj.appid,
        "timestamp": res.obj.timestamp,
        "nonceStr": res.obj.nonceStr,
        "signature": res.obj.signature,
        "jsApiList": ['WeixinJSBridge']
      })
      console.log('调用微信支付')
      console.log(this.requestSecret)
      console.log(this.product_id)
      http.post('http://www.qqchou.org/zfzx/api', {'appKey': '402880e75f1520d3015f152167180000', 'requestSecret': this.requestSecret, 'type': '11', product_id: this.product_id, openid: this.openid, callBackUrl: encodeURI(CONSTANT.RECEIPT_ACHIEVE), 'orderInfo': '{"count": 1,"product_id":"' + this.product_id + '", "product_name": "' + this.theme + '","product_detail": "' + this.eventAbstract + '","price":' + this.money + '}'}, (res) => {
        console.log(res)
        if (res.code == 200) {
          this.paySignObj = res.obj
          this.callPay()
        } else {
          alert('提交订单失败！')
        }
      })
    }
  })
  // this.wx.WeixinJSBridge.invoke('sendAppMessage', {
  //   // "appid":appId,
  //   // "img_url":imgUrl,
  //   //"img_width":"640",
  //   //"img_height":"640",
  //   "link":link,
  //   "desc":desc,
  //   "title":title
  // });
}
// module.exports = weixinSendAppMessage

